const Router = require('koa-router')

//判断登录
const { auth, handAdminPermission } = require('../middleware/auth_middleware')

//导入参数校验中间件
const { validator } = require('../middleware/goods_middle')

const router = new Router({ prefix: '/goods' })

const { upload, create, update, remove, Goodsdown, Goodsup, findAll } = require('../controller/goods_controller')
//  auth, handAdminPermission,
router.post('/upload', upload)

//发布商品接口
router.post('/', auth, handAdminPermission, validator, create)

//更改商品接口
router.put('/:id', auth, handAdminPermission, validator, update)

// 删除商品(硬删除)
router.delete('/:id', auth, handAdminPermission, remove)

//下架商品
router.post('/:id/off', auth, handAdminPermission, Goodsdown)

//上架商品
router.post('/:id/up', auth, handAdminPermission, Goodsup)


//获取商品
router.get('/', findAll)

module.exports = router